home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 5 / CRON_1 / CRON_SET / CRON / ARGC_BUI.C next >
Text File  |  1991-09-22  |  3KB  |  118 lines

  1. /*    ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  2.     
  3.     Filename: "argc Builder.c"
  4.     argc/argv argument construction and transmission code, written for 
  5.         THINK C 5.0
  6.     By Chris Johnson
  7.     Version of: Sunday, September 15, 1991 7:00 PM
  8.     
  9.     Distribute freely and without charge, but say something nice about 
  10.     the author when you use it.  Please send me a copy of any improve-
  11.     ments you make so they can be incorporated into future versions.
  12.     
  13.     ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  14.     Internet:    chrisj@emx.utexas.edu
  15.     UUCP:        {husc6|uunet}!cs.utexas.edu!ut-emx!chrisj
  16.     BitNet:        chrisj@utxvm.bitnet
  17.     AppleLink:    chrisj@emx.utexas.edu@internet#
  18.     CompuServe:    >INTERNET:chrisj@emx.utexas.edu
  19.     US Mail:    Chris Johnson, 3311 Red River #305, Austin, TX 78705
  20.     ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤    */
  21.  
  22.  
  23. #include "argc Builder.h"
  24. #include "StrBuff Arg Util.h"
  25. #include ":::Standard Code:BufferMgr.h"
  26.  
  27.  
  28. #define argcEventClass        'args'
  29. #define argcEventID            'argc'
  30. #define argcKeyword            'argc'
  31.  
  32.  
  33.  
  34.  
  35. OSErr argcCreate(argcDesc)
  36. AEDesc                    *argcDesc;
  37. {
  38.     return (AECreateList(NULL, 0, FALSE, argcDesc));
  39. }
  40.  
  41.  
  42. OSErr argcDispose(argcDesc)
  43. AEDesc                    *argcDesc;
  44. {
  45.     return (AEDisposeDesc(argcDesc));
  46. }
  47.  
  48.  
  49. OSErr argcAddP(argcDesc, ArgStringP)
  50. AEDesc                    *argcDesc;
  51. StringPtr                ArgStringP;
  52. {
  53.     return (AEPutPtr(argcDesc, 0, typeChar, (Ptr) ArgStringP + 1, *ArgStringP));
  54. }
  55.  
  56.  
  57. OSErr argcAddC(argcDesc, ArgStringC)
  58. AEDesc                    *argcDesc;
  59. unsigned char            *ArgStringC;
  60. {
  61.     long                    ArgStringLen;
  62.     unsigned char            *ArgChar;
  63.     
  64.     ArgStringLen = 0;
  65.     ArgChar = ArgStringC;
  66.     
  67.     while (*ArgChar++ != '\0')
  68.         ArgStringLen++;
  69.     
  70.     return (AEPutPtr(argcDesc, 0, typeChar, (Ptr) ArgStringC, ArgStringLen));
  71. }
  72.  
  73.  
  74. OSErr argcAddB(argcDesc, Buffer, BuffSize)
  75. AEDesc                    *argcDesc;
  76. Ptr                        Buffer;
  77. long                    BuffSize;
  78. {
  79.     return (AEPutPtr(argcDesc, 0, typeChar, Buffer, BuffSize));
  80. }
  81.  
  82.  
  83. OSErr argcSend(argcDesc, ProcessNumber)
  84. AEDesc                    *argcDesc;
  85. ProcessSerialNumber        *ProcessNumber;
  86. {
  87.     OSErr                    OSError;
  88.     AEAddressDesc            Target;
  89.     
  90.     OSError = AECreateDesc(typeProcessSerialNumber, (Ptr) ProcessNumber, sizeof(*ProcessNumber), &Target);
  91.     if (OSError == noErr) {
  92.         AppleEvent                argcEvent;
  93.         
  94.         OSError = AECreateAppleEvent(argcEventClass, argcEventID, &Target, kAutoGenerateReturnID, 0, &argcEvent);
  95.         if (OSError == noErr) {
  96.             
  97.             OSError = AEPutParamDesc(&argcEvent, argcKeyword, argcDesc);
  98.             if (OSError == noErr) {
  99.                 AppleEvent                argcReplyEvent;
  100.                 
  101.             //    Note that we won't have to dispose of the reply event because
  102.             //    we specify kAENoReply when we send the original event.
  103.                 
  104.                 OSError = AESend(&argcEvent, &argcReplyEvent, kAENoReply, kAENormalPriority, kAEDefaultTimeout, NULL, NULL);
  105.             }
  106.             
  107.             AEDisposeDesc(&argcEvent);
  108.         }
  109.         
  110.         AEDisposeDesc(&Target);
  111.     }
  112.     
  113.     return (OSError);
  114. }
  115.  
  116.  
  117.  
  118.